<template>
  <div>
    <router-link to="/my" slot="left">
    <div class="head">

      <div class="head-left"><img src="../../assets/icon/common-left.png" alt=""></div>
      <div class="head-right">簽約</div>
    </div>
      </router-link>
    <div class="content">
      <div class="content-top">BTC錢包地址</div>
      <div class="content-bottom">
        <textarea style="background:AliceBlue" v-model="BTC" @focus="one(this)" rows="6"
                  cols="52">
        </textarea>
      </div>
    </div>
    <div class="content">
      <div class="content-top">USDT錢包地址</div>
      <div class="content-bottom">
        <textarea style="background:AliceBlue" v-model="USDT" @focus="two(this)"  rows="6" cols="52">
        </textarea>
      </div>
    </div>
    <div class="content">
      <div class="content-top">ETH錢包地址</div>
      <div class="content-bottom">
        <textarea style="background:AliceBlue" v-model="ETH" @focus="three(this)" rows="6" cols="52">
        </textarea>
      </div>
    </div>

    <div class="input-item">
      <input type="text" v-model="msg_code" placeholder="請輸入郵箱驗證碼">
      <div class="get-code-btn" @click="wentCode()"  v-show="show">獲取驗證碼</div>
      <div class="get-code-btn" v-show="!show">{{count}}</div>
    </div>
    <mt-button type="primary" @click="qy" class="login-submit" :style="{marginTop:'14px'}">提交</mt-button>

  </div>
</template>

<script>
  import {Field, Header, Button, MessageBox} from 'mint-ui';
  import Vue from 'vue';
  import {sign} from '../../api/sign'
  import {goCode} from 'api/getCode'
  Vue.component(Header.name, Header);
  Vue.component(Field.name, Field);
  Vue.component(Button.name, Button);
  export default {
    name: "sign",
    data() {
      return {
        msg_code:'',
        count: '',
        show: true,
        BTC:'請輸入BTC錢包地址',
        USDT:'請輸入USDT錢包地址',
        ETH:'請輸入ETH錢包地址',
        userInfo:{},
      }
    },
    methods: {
      // input框获取焦点
      one() {
        if (this.BTC == '請輸入BTC錢包地址') this.BTC = '';
      },
      two() {
        if (this.USDT == '請輸入USDT錢包地址') this.USDT = '';
      },
      three() {
        if (this.ETH == '請輸入ETH錢包地址') this.ETH = ''
      },
      //签约
      qy() {
        if (this.BTC == '請輸入BTC錢包地址') {
          MessageBox.alert('請正確輸入BTC錢包地址')
        } else if(this.USDT == '請輸入USDT錢包地址'){
          MessageBox.alert('請正確輸入USDT錢包地址')
        }else if (this.ETH == '請輸入ETH錢包地址'){
          MessageBox.alert('請正確輸入ETH錢包地址')
        }else{
          sign({
            btc_address: this.BTC,
            usdt_address: this.USDT,
            eth_address: this.ETH
          }).then((data) => {
            if (data.errorCode == 0) {
              MessageBox.alert(data.msg).then(action => {
                this.myMoney = this.myMoney - this.amount
              })
            } else {
              MessageBox.alert(data.msg)
            }
          })
        }
      },
      wentCode(){

     this.email=this.userInfo.utel

          goCode({mail:this.email}).then((data)=>{
            if (data.errorCode!=0){
              MessageBox.alert(data.msg)
            }else {
              const TIME_COUNT = 60;
              if (!this.timer) {
                this.count = TIME_COUNT;
                this.show = false;
                this.timer = setInterval(() => {
                  if (this.count > 0 && this.count <= TIME_COUNT) {
                    this.count--;
                  } else {
                    this.show = true;
                    clearInterval(this.timer);
                    this.timer = null;
                  }
                }, 1000)

              }
            }
          });





      },
      allMoney() {
        this.amount = this.myMoney
      }
    },

    mounted() {
      this.userInfo = window.localStorage.getItem('userInfo');
    }

  }
</script>

<style scoped>
  .head {
    width: 100%;
    display: flex;
    height: 40px;
    flex-direction: row;
    font-size: 16px;
    font-weight: bold;
    line-height: 40px;
  }

  .head-left {
    width: 40%;
    height:40px ;
    margin-left: 4%;
  }
  .head-left img {
   width: 12px;
    margin-top: 10px;
  }
  .head-right {
    width: 40%;
  }

  .content {
    width: 100%;
    height: 140px;
  }

  .content-top {
    width: 80%;
    margin-left: 4%;
    font-size: 14px;
    height: 24px;
    line-height: 24px;
    margin-top: 10px;
  }

  .content-bottom {
    margin-left: 4%;
    font-size: 12px;
  }

  .get-code-btn {
    width: 89px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #409EFF;
    background: #B3D8FF;
    margin-left: 10px;
    cursor: pointer;
    font-size: 11px;
    font-weight: normal;
  }

  .input-item #msg-code {
    width: 80px;
  }

  .input-item {
    margin-bottom: 10px;
    width: 80%;
    display: flex;
    align-items: center;
    height: 36px;
    margin-left: 10%;
    margin-top: 20px;
  }

  .input-item input {
    flex: 1;
    padding-left: 11px;
    width: 50%;
    color: #C0C4CC;
    font-size: 11px;
    height: 34px;
    border: 1px solid #C0C4CC;
  }

  .login-submit {
    width: 80%;
    margin-left: 10%;
    height: 46px;
    margin-top: 26px;
    background: #409EFF;
    color: #FFFFFF;
    font-weight: 100;
    font-size: 16px;
  }
</style>
